#!/usr/bin/env bash

# ----------------------------------------------------------------------
# Filename	:  15-UID-lv4.sh
# Version	:  1.0
# Date		:  2020/05/22
# Author	:  Lz
# Email		:  lz843723683@gmail.com
# History	:     
#             Version 1.0, 2020/05/22
# Function	： 测试安全四级-用户标识
# Out		:        
#              0 => TPASS
#              1 => TFAIL
#              other=> TCONF
# ----------------------------------------------------------------------

## TODO : 测试收尾清除工作
#
UIDClean_FTLV4(){
	userdel -rf $User_Lv4 &>/dev/null

	return $TPASS
}


## TODO: 调用程序退出函数
#    In: $1 => 调用脚本结果值
UIDExit_FTLV4(){
        # 调用退出函数，其中调用了clean相关函数
	Exit_FTLIB ${1}
}


## TODO: 用户界面
#
UIDUSAGE_FTLV4(){
	USAGE_FTLIB "安全四级测试 - 用户标识"
}


## TODO : 测试前的初始化 
#  Out  : 
#         0 => TPASS
#         1 => TFAIL
#         other=> TCONF
UIDInit_FTLV4(){
        # 调用初始化函数
	Init_FTLIB "UIDClean_FTLV4"
        # 调用用户界面函数
 	UIDUSAGE_FTLV4

	# 用户名
	User_Lv4="testltf-uid-lv4"
}


## TODO ：用户标识UID不一样
#
UIDTest01_FTLV4(){
	# 临时用户
	local tmpuser="$User_Lv4"
	# UID号
	local uid_1=""
	local uid_1=""

	# 如果存在用户则删除	
	userdel -rf $tmpuser &>/dev/null
	useradd $tmpuser  &>/dev/null

	# 获取UID
	uid_1=$(id -u ${tmpuser})
	echo "新建用户 ${tmpuser} 的UID: $uid_1"

	userdel -rf $tmpuser &>/dev/null
	useradd $tmpuser  &>/dev/null
	# 获取UID
	uid_2=$(id -u ${tmpuser})
	echo "删除后重建用户 ${tmpuser} 的UID: $uid_2"

	userdel -rf $tmpuser &>/dev/null
	
	if [ "Z$uid_1" != "Z$uid_2" ];then
	# UID不一致
		OutputRet_FTLIB ${TPASS}
		RetParse_FTLIB "要求两次UID 不一致" "False"
	else
		OutputRet_FTLIB ${TFAIL}
		RetParse_FTLIB "要求两次UID 不一致" "False"
	fi
}


## TODO : Main
#  Out  : 
#         0 => TPASS
#         1 => TFAIL
#         other => TCONF
UIDMain_FTLV4(){
	UIDInit_FTLV4

	UIDTest01_FTLV4

	return ${TPASS}	
}

UIDMain_FTLV4
UIDExit_FTLV4 $?
